package com.security.it.web.filter;

import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

@Slf4j
//@Component
public class TimeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("init time filetr");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info("start time filetr");
        Stopwatch stopwatch = Stopwatch.createStarted();
        chain.doFilter(request, response);
        log.info("chain service times: {}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        log.info("end time filetr");
    }

    @Override
    public void destroy() {
        System.out.println("destroy time filetr");
    }
}
